<?php

$appid = "wx1437004ca43ac546";
$appsecret = "d2e8e193333f1e4e5f462b50cd14f1ef";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";

$output = https_request($url);
$jsoninfo = json_decode($output, true);

$access_token = $jsoninfo["access_token"];


$jsonmenu = '{
      "button":[
      {
            "name":"个人中心",
           "sub_button":[
            {
               "type":"click",
               "name":"个人信息",
               "key":"个人信息"
            },
            {
                "type":"view",
                "name":"进入中心",
                "url":"http://m.hao123.com/a/tianqi"
            }]
      

       },
       {
           "name":"亲人列表",
           "type":"view",
           "url":"http://m.hao123.com/a/tianqi"
       },
	   {
           "name":"登陆注册",
           "type":"view",
           "url":"http://m.hao123.com/a/tianqi"
       } 
		]
 }';


$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
$result = https_request($url, $jsonmenu);
var_dump($result);

function https_request($url,$data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

?>